Flow control in Java with Threads